#include <stdio.h>

struct student
{
	char name[10];
	int number;
};

int main(int argc, char *argv[]) 
{
	FILE *fp = NULL;
	int i;
	struct student boya[2], boyb[2], *pp, *qq;
	if((fp = fopen("student", "w+")) == NULL) {
		printf("can not open student \n");
		return -1;
	}
	pp = boya;
	qq = boyb;
	printf("please input two student 'name and number:'\n");
	for(i = 0; i < 2; ++i, pp++) {					//input two students
		scanf("%s\t%d", pp->name, &pp->number);
	}
	pp = boya;
	fwrite(pp, sizeof(struct student), 2, fp);		//write two students into file
	rewind(fp);										//relocate the w/r point to file head
	fread(qq, sizeof(struct student), 2, fp);		//read two students from file
	printf("name\t\tnumber\n");
	for(i = 0; i < 2; i++, qq++) {					//output two students
		printf("%s\t\t%d\n", qq->name, qq->number);
	}
	fclose(fp);
	return 0;
}
